/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.app.pay.order.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.app.pay.order.entity.AppPayOrder;
import com.jeesite.modules.app.pay.order.service.AppPayOrderService;

/**
 * 支付管理Controller
 * @author zpp
 * @version 2020-03-13
 */
@Controller
@RequestMapping(value = "${adminPath}/app/pay/order/appPayOrder")
public class AppPayOrderController extends BaseController {

	@Autowired
	private AppPayOrderService appPayOrderService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public AppPayOrder get(String id, boolean isNewRecord) {
		return appPayOrderService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("app:pay:order:appPayOrder:view")
	@RequestMapping(value = {"list", ""})
	public String list(AppPayOrder appPayOrder, Model model) {
		model.addAttribute("appPayOrder", appPayOrder);
		return "modules/app/pay/order/appPayOrderList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("app:pay:order:appPayOrder:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<AppPayOrder> listData(AppPayOrder appPayOrder, HttpServletRequest request, HttpServletResponse response) {
		appPayOrder.setPage(new Page<>(request, response));
		Page<AppPayOrder> page = appPayOrderService.findPage(appPayOrder);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("app:pay:order:appPayOrder:view")
	@RequestMapping(value = "form")
	public String form(AppPayOrder appPayOrder, Model model) {
		model.addAttribute("appPayOrder", appPayOrder);
		return "modules/app/pay/order/appPayOrderForm";
	}

	/**
	 * 保存支付管理
	 */
	@RequiresPermissions("app:pay:order:appPayOrder:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated AppPayOrder appPayOrder) {
		appPayOrderService.save(appPayOrder);
		return renderResult(Global.TRUE, text("保存支付管理成功！"));
	}
	
	/**
	 * 停用支付管理
	 */
	@RequiresPermissions("app:pay:order:appPayOrder:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(AppPayOrder appPayOrder) {
		appPayOrder.setStatus(AppPayOrder.STATUS_DISABLE);
		appPayOrderService.updateStatus(appPayOrder);
		return renderResult(Global.TRUE, text("停用支付管理成功"));
	}
	
	/**
	 * 启用支付管理
	 */
	@RequiresPermissions("app:pay:order:appPayOrder:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(AppPayOrder appPayOrder) {
		appPayOrder.setStatus(AppPayOrder.STATUS_NORMAL);
		appPayOrderService.updateStatus(appPayOrder);
		return renderResult(Global.TRUE, text("启用支付管理成功"));
	}
	
	/**
	 * 删除支付管理
	 */
	@RequiresPermissions("app:pay:order:appPayOrder:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(AppPayOrder appPayOrder) {
		appPayOrderService.delete(appPayOrder);
		return renderResult(Global.TRUE, text("删除支付管理成功！"));
	}
	
}